var _n31;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$EventManager = require("EventManager");
var s = cc__importDefault($1$EventManager);
var $1$Loader = require("Loader");
var c = cc__importDefault($1$Loader);
var $1$yyComponent = require("yyComponent");
var l = cc__importDefault($1$yyComponent);
var $GameEventType = require("GameEventType");
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_PifuPageItem = function (t) {
  function _ctor() {
    // 使用 let 关键字定义局部变量，确保其作用域限制
    let instance = null !== t && t.apply(this, arguments) || this;

    // 初始化所有实例属性
    instance.icon = null;            // 图标属性
    instance.lockNodebg = null;      // 锁定节点背景
    instance.lockNode = null;        // 锁定节点
    instance.xuanzhong = null;       // 选择状态
    instance.leixing = "";            // 类型属性，初始化为空字符串
    instance.index = 0;              // 索引属性，初始化为0

    // 返回实例对象
    return instance;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.start = function () {
    this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
    this.on($GameEventType.EventType.DirectorEvent.pifugenghuan, this.updataView, this);
  };
  _ctor.prototype.setIcon = function (t, e) {
    // 代码块处理类的某些用户界面和数据逻辑
    var instance = this; // 使用此上下文
    this.leixing = t;    // 更新类型属性
    this.index = e;      // 更新索引属性

    // 加载某个资源并处理回调
    c.default.loadBundleRes("home", "rank/" + t + "/" + t + e, function (resource) {
      if (instance && instance.node) {
        var spriteComponent = instance.icon.getComponent(cc.Sprite);
        var width = resource.width;
        var height = resource.height;

        // 更新图标的尺寸
        instance.icon.node.width = width;
        instance.icon.node.height = height;
        spriteComponent.spriteFrame = new cc.SpriteFrame(resource); // 设置新的精灵框架
      }
    });

    this.updataView(); // 更新视图

    var userLevel = $zqcc_OverallSystem.sers().userSrv.getFeibiaoData().level; // 获取用户等级
    // 判断锁定状态，根据索引和等级启用或禁用节点和背景
    if ([0, 1, 2, 4, 6, 9, 12, 15, 19, 23, 27, 31, 36, 41, 46, 51][this.index - 1] < userLevel || this.index === 1) {
      this.lockNode.active = false;  // 解锁状态
      this.lockNodebg.active = false; // 解锁背景
    } else {
      this.lockNode.active = true;   // 锁定状态
      this.lockNodebg.active = true; // 锁定背景
    }

  };
  _ctor.prototype.updataView = function () {
    var userSelection = $zqcc_OverallSystem.sers().userSrv.getQiqiupifu(); // 获取用户偏好数据

    // 检查用户的类型和索引是否与当前相同
    if (userSelection.leixing === this.leixing && userSelection.index === this.index) {
      this.xuanzhong.active = true;   // 激活选择状态
      this.lockNode.active = false;    // 禁用锁定节点
    } else {
      this.xuanzhong.active = false;  // 禁用选择状态
    }
  };
  _ctor.prototype.onTouchStart = function () {
    // 播放按钮的音效
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();

    // 检查锁定状态
    if (this.lockNode.active) {
      // 获取当前索引对应的解锁关卡编号
      var levelIndex = [0, 1, 2, 4, 6, 9, 12, 15, 19, 23, 27, 31, 36, 41, 46, 51][this.index - 1];
      // 显示解锁提示消息
      $zqcc_OverallSystem.sers().uiSrv.showMessage("通过第" + levelIndex + "关解锁");
    } else {
      // 创建包含类型和索引的对象
      var userPreference = {
        leixing: this.leixing,
        index: this.index
      };
      // 设置用户偏好
      $zqcc_OverallSystem.sers().userSrv.setQiqiupifu(userPreference);
      // 触发皮肤更新事件
      s.default.emit($GameEventType.EventType.DirectorEvent.pifugenghuan);
    }
  };
  cc__decorate([ccp_property(cc.Sprite)], _ctor.prototype, "icon", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "lockNodebg", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "lockNode", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "xuanzhong", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(l.default);
exports.default = def_PifuPageItem;